package main

import (
	"fmt"
	"sync"
)

type worker struct {
	in chan int
	nodifyFunc func()
}

func changeDemo(){
	//这个channel是接收数据的
	var workers [10]worker
	var wg sync.WaitGroup

	for i :=0; i<10; i++{
		workers[i] = createWorker(i, &wg)
	}

	wg.Add(20)
	for i,w:= range workers {
		w.in <-  'a'+i
	}
	for i,w:= range workers {
		w.in <-  'A'+i
	}

	wg.Wait()

}

func doWorker(id int, w worker)  {
	//接收消息
	for n:= range w.in{
		fmt.Printf("workder =%d, receiver =%c\n", id, n)
		//并行的发送确认信息
		w.nodifyFunc()
	}
}

func createWorker(id int, wg *sync.WaitGroup) worker {
	w := worker{
		make(chan int),
		func(){
			wg.Done()
		},
	}
	//并行的接收信息
	go doWorker(id, w)
	return w
}

func main() {
	changeDemo()
}
